# 导包
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
# 导入用来做鼠标一系列操作的类 ActionChains
from selenium.webdriver.common.action_chains import ActionChains
# 引入模拟键盘一系列操作类 Keys
from selenium.webdriver.common.keys import Keys

# 实例化浏览器
driver = webdriver.Edge()

# 网址
my_url = 'https://www.leafground.com/input.xhtml'

# 打开网页
driver.get(my_url)

# 窗口最大化
driver.maximize_window()

# 定位到多行文本框
lines_element = driver.find_element(By.ID, 'j_idt88:j_idt101')
lines_element.send_keys('多行文本框第一行')

# 模拟键盘回车键
ActionChains(driver).send_keys(Keys.ENTER).perform()
lines_element.send_keys('第二行文字')

# 模拟鼠标的操作
# 1、点击（左键单击）-- click
driver.find_element(By.ID, 'j_idt88:j_idt101').click()

# 2、右键点击（右3键单击）-- context_click
ele = driver.find_element(By.ID, 'j_idt88:j_idt101')
ActionChains(driver).context_click(ele).perform()

# 3、双击（左键快速两次点击）-- double_click
double_ele = driver.find_element(By.ID, 'j_idt88:j_idt91')
ActionChains(driver).double_click(double_ele).perform()

# 4、鼠标悬停 -- move_to_element
move_element = driver.find_element(By.XPATH, '//*[@id="menuform:j_idt40"]/a/i[1]')
ActionChains(driver).move_to_element(move_element).perform()

# 5、拖拽操作 -- drag_and_drop
# 假如有 source和target 元素
# source = driver.find_element(By.ID, 'source')
# target = driver.find_element(By.ID, 'target')
# 把 source 元素 拖拽至 target 元素
# ActionChains(driver).drag_and_drop(source, target).perform()

# 6、鼠标滚动
# 向下滚动
# ActionChains(driver).move_by_offset(100, 500).perform()
# 使用JavaScript来执行向下滚动到页面底部
driver.execute_script('window.scrollTo(0, document.body.scrollHeight);')

# 等待3秒
sleep(3)

# 关闭实例化浏览器
driver.quit()
